import {
	put,
	takeEvery
} from 'redux-saga/effects';

import {
	GET_TODO_LIST
} from './ActionTypes';

import {
	getInitListAction
} from './ActionCreators';

import axios from 'axios';

function* getInitList() {
	try {
		const res = yield axios.get("http://localhost:8083/auth/v1/todoList");
		const action = getInitListAction(res.data);
		yield put(action);
	} catch (e) {
		alert("初始化数据异常！");
	}

	// axios.get("http://localhost:8083/auth/v1/todoList").then((res) => {
	// 	const data = res.data;
	// 	const action = getInitListAction(data);
	// 	put(action);
	// });
}

function* mySaga() {
	yield takeEvery(GET_TODO_LIST, getInitList);
}

export default mySaga;